package com.demo01.demo.Repository;

import com.demo01.demo.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User,String> {
    public Optional<User> findByName(String user_name);
    @Query(value = "select * from test.user where if(?1!='',user_id= ?1,true) and if(?2!='',user_name= ?2,true) and if(?3!='',user_active= ?3,true) and if(?4!='',province= ?4,true) and if(?5!='',city= ?5,true) ",nativeQuery = true)
    public Page<User> find(String sql1, String sql2, String sql3,String sql4,String sql5, Pageable pageable);
    @Query(value = "select * from test.user where if(?1!='',user_id= ?1,true) and if(?2!='',user_name= ?2,true) and if(?3!='',user_active= ?3,true) and if(?4!='',province= ?4,true) and if(?5!='',city= ?5,true) ",nativeQuery = true)
    public List<User> searchall(String sql1, String sql2, String sql3, String sql4, String sql5);
}
